home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SOUND.SWG / 0051_S3M header.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  6KB  |  131 lines

  1. {
  2. From: jurip@clinet.fi (Juri Pakaste)
  3.  
  4. Hopefully someone here has experience reading S3M headers...
  5. I'm trying to read the S3M header. I get the name right, I think
  6. I get the number of instruments right, but I can't get the number
  7. of patterns right. If I understand correctly the file which comes
  8. with Scream Tracker 3.01 (see below), the number of patterns
  9. should be located in bytes 35-36 (why on earth two bytes? Who
  10. would use over 255 patterns?). The numbers I get have nothing to
  11. do with numbers DMP and Inertia Player give, though. My little test-
  12. program, S3MREAD.EXE, tells me, for example, that a module that has
  13. 55 (I think) patterns, has in fact 99. Just great. Some of the values
  14. it gives manage to get pretty near the ones DMP and IPlay give,
  15. but... you get the idea.
  16.  
  17. Here is there relevant part of S3M technical documentation:
  18.  
  19. ------------------------------------8<----------------------------------
  20.  
  21.                                 Song/Module header
  22.           0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  23.         -----------------------------------------------------------------
  24.   0000: | Song name, max 28 chars (incl. NUL)                           |
  25.         |---------------------------------------------------------------|
  26.   0010: |                                               |1Ah|Typ| x | x |
  27.         |---------------------------------------------------------------|
  28.   0020: |OrdNum |InsNum |PatNum | Flags | Cwt/v |  Ffv  |'S'|'C'|'R'|'M'|
  29.         |---------------------------------------------------------------|
  30.   0030: |m.v|i.s|i.t|m.m| x | x | x | x | x | x | x | x | x | x | x | x |
  31.         |---------------------------------------------------------------|
  32.   0040: |Channel settings for 32 channels, 255=unused,+128=disabled     |
  33.         |---------------------------------------------------------------|
  34.   0050: |                                                               |
  35.         |---------------------------------------------------------------|
  36.   0060: |Orders; length=OrdNum (must be even)                           |
  37.         |---------------------------------------------------------------|
  38.   xxxx: |Parapointers to instruments; length=InsNum*2                   |
  39.         |---------------------------------------------------------------|
  40.   xxxx: |Parapointers to patterns; length=PatNum*2                      |
  41.         -----------------------------------------------------------------
  42.  
  43.  
  44.         Typ     = File type: 16=module,17=song
  45.         Ordnum  = Number of orders in file
  46.         Insnum  = Number of instruments in file
  47.         Patnum  = Number of patterns in file
  48.         Cwt/v   = Created with tracker / version: &0xfff=version, >>12=tracker
  49.                         ST30:0x1300
  50.         Ffv     = File format version;
  51.                         1=original
  52.                         2=original BUT samples unsigned
  53.         Parapointers are OFFSET/16 relative to the beginning of the header.
  54.  
  55.         PLAYING AFFECTORS / INITIALIZERS:
  56.         Flags   =  +1:st2vibrato 
  57.                    +2:st2tempo
  58.                    +4:amigaslides
  59.                    +8:0vol optimizations
  60.                    +16:amiga limits
  61.                    +32:enable filter/sfx
  62.         m.v     = master volume
  63.         m.m     = master multiplier (&15) + stereo(=+16)
  64.         i.s     = initial speed (command A)
  65.         i.t     = initial tempo (command T)
  66.  
  67.         Channel types:
  68.         &128=on, &127=type: (127=unused)
  69.         8  - L-Adlib-Melody 1 (A1)      0  - L-Sample 1 (S1)
  70.         9  - L-Adlib-Melody 2 (A2)      1  - L-Sample 2 (S2)
  71.         10 - L-Adlib-Melody 3 (A3)      2  - L-Sample 3 (S3)
  72.         11 - L-Adlib-Melody 4 (A4)      3  - L-Sample 4 (S4)
  73.         12 - L-Adlib-Melody 5 (A5)      4  - R-Sample 5 (S5)
  74.         13 - L-Adlib-Melody 6 (A6)      5  - R-Sample 6 (S6)
  75.         14 - L-Adlib-Melody 7 (A7)      6  - R-Sample 7 (S7)
  76.         15 - L-Adlib-Melody 8 (A8)      7  - R-Sample 8 (S8)
  77.         16 - L-Adlib-Melody 9 (A9)
  78.                                         26 - L-Adlib-Bassdrum (AB)
  79.         17 - R-Adlib-Melody 1 (B1)      27 - L-Adlib-Snare    (AS)
  80.         18 - R-Adlib-Melody 2 (B2)      28 - L-Adlib-Tom      (AT)
  81.         19 - R-Adlib-Melody 3 (B3)      29 - L-Adlib-Cymbal   (AC)
  82.         20 - R-Adlib-Melody 4 (B4)      30 - L-Adlib-Hihat    (AH)
  83.         21 - R-Adlib-Melody 5 (B5)      31 - R-Adlib-Bassdrum (BB)
  84.         22 - R-Adlib-Melody 6 (B6)      32 - R-Adlib-Snare    (BS)
  85.         23 - R-Adlib-Melody 7 (B7)      33 - R-Adlib-Tom      (BT)
  86.         24 - R-Adlib-Melody 8 (B8)      34 - R-Adlib-Cymbal   (BC)
  87.         25 - R-Adlib-Melody 9 (B9)      35 - R-Adlib-Hihat    (BH)
  88.  
  89. So, shouldn't this piece of code be able to read the name,
  90. number of instruments and number of patterns right:
  91.  
  92. }
  93. Program S3MReader;
  94. Var
  95.    NameArray       :       Array [1..28] Of Char;
  96.    InstrArray, PatArray : Array [1..2] Of Byte;
  97.    InstrByte, PatByte   :       Byte;
  98.    f : File;
  99.    i       :       Integer;
  100.    j       :       Integer;
  101.    S3MName :       String;
  102.  
  103. Begin
  104.    WriteLn;
  105.    WriteLn;
  106.    If ParamCount = 1 Then
  107.    Begin
  108.       Assign(f,ParamStr(1));
  109.       Reset(f,1);
  110.       BlockRead(f,NameArray,28,i);
  111.       For j := 1 To 28 Do S3MName := S3MName + NameArray[j];
  112.       j := 28;
  113.       While (Ord(S3MName[Length(S3MName)]) = 0) Or (Ord(S3MName
  114.    (continues...)[Length(S3MName)]) = 32) Do
  115.       Begin
  116.          j := j - 1;
  117.          S3MName[0] := Chr(j);
  118.       End;
  119.       Seek(f,33);
  120.       BlockRead(f,InstrArray,2,i);
  121.       InstrByte := InstrArray[1] + InstrArray[2];
  122.       BlockRead(f,PatArray,2,i);
  123.       PatByte := PatArray[1] + PatArray[2];
  124.       WriteLn('Name: ',S3MName);
  125.       WriteLn('Number of instruments: ',InstrByte);
  126.       WriteLn('Number of patterns: ',PatByte);
  127.       Close(f);
  128.    End;
  129. End.
  130.  
  131.